/**
 *
 */
package jp.seraph.jspf.pose;

import jp.seraph.jsade.action.AgentAction;
import jp.seraph.jsade.core.World;
import jp.seraph.jsade.task.AgentTask;
import jp.seraph.jsade.task.TaskSelector;
import jp.seraph.jsade.util.Executor;

/**
 * 一つのPoseSetのみを保持するPoseSelector
 */
public class MonoPoseSelector implements TaskSelector {
    public MonoPoseSelector(PoseSet aSet) {
        mSet = aSet;
        mReturn = true;
    }

    private PoseSet mSet;
    private boolean mReturn;

    /**
     *
     * @see jp.seraph.jsade.task.TaskSelector#selectTask(jp.seraph.jsade.core.World)
     */
    public AgentTask selectTask(World aWorld) {
        if (!mReturn)
            return null;

        mReturn = false;
        AgentTask tResult = mSet.toTask();
        Executor tExecuter = new Executor(){
            public void execute(){
                mReturn = true;
            }
        };

        tResult.addCanceledListener(tExecuter);
        tResult.addCompletedListener(tExecuter);

        return tResult;
    }

    /**
     *
     * @see jp.seraph.jsade.task.TaskSelector#getAgentAction(jp.seraph.jsade.core.World)
     */
    public AgentAction getAgentAction(World aWorld) {
        return null;
    }

}
